%% FRED_analysis.m
%
% Laibson, Maxted, and Moll
% Analyze FRED data for model calibration
%--------------------------------------------------------------------------


%--------------------------------------------------------------------------
%% 2015-2017 Interest Rate Wedges
clear all;
raw_data_FRED = readtable('data/Monthly FRED.xls', 'Range', 'A14:E50');
    ccInds = find(table2array(raw_data_FRED(:,5)) > 0.001);
    
ccWedge1517 = round(mean(table2array(raw_data_FRED(ccInds,5)) - table2array(raw_data_FRED(ccInds,2))), 2)
mortgageWedge1517 = round(mean(table2array(raw_data_FRED(:,3)) - table2array(raw_data_FRED(:,2))), 2)
ARMWedge1517 = round(mean(table2array(raw_data_FRED(:,4)) - table2array(raw_data_FRED(:,2))), 2)
 

%--------------------------------------------------------------------------
%% AR(1) for TIPS (Weekly Data)
raw_data_10YT = readtable('data/Weekly FRED.xls', 'Range', 'A11:B897');
Delta = 1/52;

EstMdl = estimate(arima(1,0,0),table2array(raw_data_10YT(:,2)));
    rho = EstMdl.AR{1};
    sig = sqrt(EstMdl.Variance);
    rate_r_OU = -log(rho)/Delta
    sig_r_OU = sqrt((sig^2*2*rate_r_OU)/(1-exp(-2*rate_r_OU*Delta)))

